<!DOCTYPE html>
<html>
<head>
    <title>设置</title>
    <meta charset="UTF-8"/>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
  
	<script type="text/javascript" src="{{ URL::asset('weixin/v1/js/main.js') }}"></script>
	<script type="text/javascript" src="{{ URL::asset('weixin/v1/js/debug.js') }}"></script>
<style type="text/css">
*{
	margin:0;
	padding:0;
}
body{
	font-family: Helvetica;
	color:#9d9d9d;
}
#bbody{
	
}
.top{
	width:100%;
	background: #ec8431;
	height: 160px;
	text-align: center;
}
.icon{
	background:url("/weixin/v1/img/user.png") no-repeat center;
	background-size:75px;
	height:75px;
	width:75px;
	border-radius: 75px;
	border:solid 2px #fff;
	position: absolute;
	left: 50%;
	margin-left: -37px;
	top:29px;
	display: block;
}
.name{
	width:100%;
	position: absolute;
	top:119px;
}
.user_name{
	display: inline;
	margin-left: -7px;
	/* color:#424242; */
	color:#4c4d4f;
	font-size: 16px;
}
#user_sex{
	position: absolute;
	margin: 0 0 0 -3px;
}
.container{
	width: 100%;
	/* color:#3E3D3E; */
	color:#4c4d4f;;
}
.device_div{
	height: 55px;
	border-bottom:solid 1px #e8e8e8;
	line-height: 55px;
}
.device_img{
	width: 30px;
	height: 30px;
	float: left;
	margin-top: 13px;
	margin-left: 10px;
}
.device_text{
	float: left;
	margin-left: 13px;
	margin-top: 1px;
}
.device_num{
	float: right;
	font-size: 13px;
	color:#a3a2a3;
	margin-top: 1px;
	margin-right: 5px;
}
.device_right{
	float: right;
	margin-top: 8px;
	margin-right:3px;
	width: 40px;
}
#naozhong{
	display:none;
}
@keyframes rotation
{
from {
	transform:rotate(0deg);
}
to {
	transform:rotate(360deg);
}
}

@-moz-keyframes rotation /* Firefox */
{
from {
	-moz-transform:rotate(0deg); 	/* IE 9 */
}
to {
	-moz-transform:rotate(360deg); 	/* IE 9 */
}
}

@-webkit-keyframes rotation /* Safari 和 Chrome */
{
from {
	-webkit-transform:rotate(0deg); /* Safari 和 Chrome */
}
to {
	-webkit-transform:rotate(360deg); /* Safari 和 Chrome */
}
}

@-o-keyframes rotation /* Opera */
{
from {
	-o-transform:rotate(0deg); 	/* Opera */
}
to {
	-o-transform:rotate(360deg); 	/* Opera */
}
}
.rotation{
	/*animation: rotation 2s linear 0s infinite ;*/
	/* Firefox: */
	/*-moz-animation: rotation 2s linear 0s infinite ;*/
	/* Safari 和 Chrome: */
	/*-webkit-animation: rotation 2s linear 0s infinite ;*/
	/* Opera: */
	/*-o-animation: rotation 2s linear 0s infinite ;*/
}
.refreshDeviceInfo{
	display:none;
}
</style>
</head>

<body id="bbody">


<input type="hidden" name="userType" id="userType" value="2"/>
<input type="hidden" name="enterpriseId" id="enterpriseId" value=""/>
<input type="hidden" name="memberId" id="memberId" value="00bd2e9abb4c46a298eb6b2962dbaf3a"/>
<input type="hidden" name="openId" id="openId" value="ouz52jiY7gfJd3vK-9K6T9mBRPuo"/>




<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="{{ URL::asset('weixin/v1/js/weixin_signature_api.js') }}"></script>

<div id="mask" style="width:100%;  position: absolute;z-index: 999;display:block;opacity: 0;"></div>
<div class="all">
	<div class="top">
		<div class="icon" id="icon"></div>
		<div class="name" id="user_name_div">
			<div class="user_name" id="user_name"></div>
			<img id="user_sex" alt="" src="/weixin/v1/img/device/man3.png" style="width:21px;height:21px;">
		</div>
	</div>
	
	<div class="container">
	
		<div class="device_div" id="device" onclick="clickHref(4);">
			<img class="device_img" src="/weixin/v1/img/device/user_info.png"/>
			<div class="device_text">个人信息</div>
			
			<img class="device_right" alt="" src="/weixin/v1/img/setting_arrow.png">
		</div>
	
		<div class="device_div" id="device" onclick="clickHref(1);">
			<img class="device_img" src="/weixin/v1/img/device/d.png"/>
			<div class="device_text">智能设备</div>
			
			<img class="device_right" alt="" src="/weixin/v1/img/setting_arrow.png">
			<div class="device_num"><font id="device_num"></font>个</div>
		</div>
		
		<div class="device_div" id="healthy" onclick="clickHref(2);">
			<img class="device_img" src="/weixin/v1/img/device/list.png"/>
			<div class="device_text">健康数据</div>
			
			<img class="device_right" alt="" src="/weixin/v1/img/setting_arrow.png">
		</div>
		
		<div class="device_div" id="naozhong" onclick="clickHref(5);">
			<img class="device_img" src="/weixin/v1/img/device/naozhong.png"/>
			<div class="device_text">智能闹钟</div>
			
			<img class="device_right" alt="" src="/weixin/v1/img/setting_arrow.png">
		</div>
		
		<div class="device_div" style="margin-bottom: 25px;"  id="help" onclick="clickHref(3);">
			<img class="device_img" src="/weixin/v1/img/device/q.png"/>
			<div class="device_text">帮助</div>
			
			<img class="device_right" alt="" src="/weixin/v1/img/setting_arrow.png">
		</div>
		
		<!-- 同步设备信息 -->
		<div id="refreshDeviceInfo" class="refreshDeviceInfo" style="height:48px;width:160px;margin:0 auto;margin-bottom: 25px;overflow: hidden;" ontouchend="synchronizationDeviceInfo()">
			<div style="width:45px;position:relative;float:left;height:48px;">
				<img src="/weixin/v1/img/device/cloud.png" style="width:45px;position:absolute;top: 50%;margin-top:-15px;">
				<img id="rotation" class="rotation" src="/weixin/v1/img/device/refresh.png" style="width:16px;position:absolute;top: 55%;margin-top:-8px;left:50%;margin-left: -8px;">	
			</div>
			
			<div style="float:right;font-size: 13px;color: #b7b7b7; line-height: 64px;">点击同步设备信息</div>
		</div>
	</div>
	
</div>
	 
</body>

<script type="text/javascript">
/* document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
	WeixinJSBridge.call('hideOptionMenu');
	}); */
var ctx="";
function hideWXOptionMenu(){
	try{
		wx.ready(function () {
			wx.hideOptionMenu();
		});
	}catch(err){
		
	}
}
window.onload = function(){
	var mask = document.getElementById("mask");
	mask.style.height = window.innerHeight + "px";


	wxcheckWXSignature();
	hideWXOptionMenu();

	ajaxDevice();
	window.addEventListener("pageshow", function(){
	    setTimeout(function(){},100); 
	}, false);
};

function clickHref(num){
	var openId=document.getElementById("openId").value;
	var memberId=document.getElementById("memberId").value;
	var userType=document.getElementById("userType").value;
	var enterpriseId=document.getElementById("enterpriseId").value;
	
	if(num==1){//智能设备		
			if(document.getElementById("device_num").innerHTML == 0){
				window.location.href = "/page/setting/deviceList?clear="+ new Date() * 1;
			}else{
				window.location.href = "/page/setting/deviceList?openId="+openId+"&&memberId="+memberId+"&&num="+new Date() * 1;	
			}
	}else if(num==2){//健康数据
		window.location.href="/page/setting/switch?memberId="+memberId+"&openId="+openId ;
	}else if(num ==3){//帮助
		window.location.href = "/page/setting/help?openId="+openId;
	}else if(num==4){
		if(userType==0 || userType==10){
			if(is202=="0"){
				window.location.href="/page/setting/info?memberId="+memberId+"&&openId="+openId+"&&userType="+userType+"&&enterpriseId="+enterpriseId+"&&clear="+ new Date() * 1;
			}else{
				window.location.href="/page/setting/info?memberId="+memberId+"&&openId="+openId+"&&userType="+userType+"&&enterpriseId="+enterpriseId+"&&clear="+ new Date() * 1;
			}
		}else{
			if(is202=="0"){
				window.location.href="/page/setting/info?memberId="+memberId+"&&openId="+openId+"&&userType="+userType+"&&enterpriseId="+enterpriseId+"&&clear="+ new Date() * 1;
			}else{
				window.location.href="/page/setting/info?memberId="+memberId+"&&openId="+openId+"&&userType="+userType+"&&enterpriseId="+enterpriseId+"&&clear="+ new Date() * 1;
			}
		}
		
	}
	
}

function ajaxDevice(){
	
	var _openId=document.getElementById("openId").value;
	var _memberId=document.getElementById("memberId").value;
	var times=new Date().getTime();
	
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json = xhr.responseText;
				var jsonData = eval( "(" + json + ")" );
				init(jsonData);
				
				isShowSyn();
				
				//关闭动画  隐藏遮罩层
				document.getElementById("rotation") && (document.getElementById("rotation").style.webkitAnimation = "");
				document.getElementById("mask").style.display = "none";
			}
		}
	};
	var url = "/api/ajax/getDeviceInfo";
	xhr.open("post", url + "?memberId="+_memberId+"&&openId="+_openId+"&&times="+times,true);
	xhr.send();
};
/**
 * 是否显示同步按钮  （用户列表为0的时候才显示同步设备信息按钮）
 * 2015-06-12 16:28:20 Cash
 */
function isShowSyn(){
	var deviceNum = document.getElementById("device_num").innerHTML;
	if(deviceNum == 0 && isSyned == false){
		document.getElementById("refreshDeviceInfo").style.display = "block";
	}else{
		document.getElementById("refreshDeviceInfo").style.display = "none";
	}
}

var is202="0";

function init(json){
	var jsondata = json.member;
	is202=json.is202;
	
	if (jsondata != null) {
		var icon = document.getElementById("icon");
		if (jsondata.headimgurl != null && jsondata.headimgurl != "") {
			var headImgUrl=jsondata.headimgurl;
			headImgUrl=headImgUrl.substring(0, (headImgUrl.length-1));
			headImgUrl+="64";
			icon.style.backgroundImage = "url(" + headImgUrl + ")";
		} else {
			icon.style.backgroundImage = "url('/weixin/v1/img/user.png')";
		}
		
		var user_name = document.getElementById("user_name");
		var name = jsondata.name;
		if(name.length > 0){
			name = cutstr(name,10);
		}
		
		user_name.innerHTML = name;
		
		var user_sex = document.getElementById("user_sex");
		if (jsondata.sex == 2) {
			user_sex_value = 2;
			user_sex.src = '/weixin/v1/img/device/weman3.png';
		} else {
			user_sex_value = 1;
			user_sex.src = '/weixin/v1/img/device/man3.png';
		}
	}
	document.getElementById("device_num").innerHTML=json.count;
	
	var _openId=document.getElementById("openId").value;
	var _memberId=document.getElementById("memberId").value;
	if(json.isNZDeivce==true){
		var naozhong = document.getElementById("naozhong");
		naozhong.style.display = "block";
		if(json.lt==1){
			var id = json.devices[0].id;
			naozhong.onclick = function(){
				window.location.href = "/lifesense-healthcenter/alarm/clocks.jsp?openId="+_openId+"&deviceId="+id+"&memberId="+_memberId;
			}
		}else{
			naozhong.onclick = function(){
				window.location.href = "/lifesense-healthcenter/alarm/device_clock_list.jsp?openId="+_openId+"&memberId="+_memberId;
			}
		}
	}
	//document.getElementById("bbody").style.display = "block";
}

function cutstr(str,len)  
{  
   var str_length = 0;  
   var str_len = 0;  
      str_cut = new String();  
      str_len = str.length;  
      for(var i = 0;i<str_len;i++)  
     {  
        a = str.charAt(i);  
        
        str_length++;
        if((/[\u4e00-\u9fa5]+/).test(a)){
        	str_length++;
        }
        
         str_cut = str_cut.concat(a);  
       
         if(str_length>len)  
         {  
        	 str_cut = str_cut.substr(0,i);
         str_cut = str_cut.concat("...");  
         return str_cut;  
         }  
    }  
    //如果给定字符串小于指定长度，则返回源字符串； 
    if(str_length<=len){  
     return  str;  
    } 
}
function isNZ(){
	
}
//是否同步中
var isSyn = 0;
//是否同步过
var isSyned = false;
/**
 * 同步微信绑定的设备信息
 * @return {[type]} [description]
 * @author	Cash
 */
function synchronizationDeviceInfo(){
	if(isSyn == 1){
		return;
	}
	document.getElementById("rotation").style.webkitAnimation = "rotation 1.5s linear 0s infinite";
	isSyn = 1;
	var openId = document.getElementById("openId").value;
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				isSyn = 0;
				var json = xhr.responseText;
				 // console.log( document.getElementById("rotation").style );
				isSyned = true;
				if(json == "success"){
					ajaxDevice();
				}else{
					console.log("同步失败！");
				}
				
			}
		}
	};
	var url = ctx + "/setting/ajax_synDeviceInfo_servlet?openId=" + openId + "&clear=" + new Date() * 1;
	xhr.open("post", url, true);
	xhr.send();
}
</script>

</html>